﻿using System;

namespace Turtle
{
    /// <summary>
    /// Turtle as normal mutable object.
    /// </summary>
    public class Turtle
    {
        public Position Position { get; private set; }
        public double Direction { get; private set; }

        private const int _delta = 1;

        public Turtle()
        {
            Position = new Position(0,0);
            Direction = 0.0;
        }
        
        public void Go()
        {
            var newX = (int) Math.Round(Position.X + _delta * Math.Cos(Direction));
            var newY = (int) Math.Round(Position.Y + _delta * Math.Sin(Direction));

             Position = new Position(newX, newY);
        }

        public void Rotate(double v)
        {
            Direction = Direction + v;
        }

    }

    public static class TurtleExtensions
    {
        public static void Left(this Turtle turtle)
        {
            turtle.Rotate(Math.PI / 2);
        }

        public static void Right(this Turtle turtle)
        {
            turtle.Rotate(-Math.PI / 2);
        }

        public static void GoSteps(this Turtle turtle, int steps)
        {
            for (int i = 1; i <= steps; i++)
            {
                turtle.Go();
            }
        }

    }
}
